<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('用户分配接口')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="role-form">
				    <input type="hidden" id="idUserOuter" name="idUserOuter" th:value="${user.idUserOuter}">
					<div class="select-list">
						<ul>
							<li>
								登录名称：<input type="text" name="loginName" th:value="${user.loginName}" disabled/>
							</li>
							<li>
								用户名称：<input type="text" name="userName" th:value="${user.userName}" disabled/>
							</li>
						</ul>
					</div>
				</form>
			</div>
	        
	        <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="selectInter()" >
	                <i class="fa fa-plus"></i> 添加接口
	            </a>
				<a class="btn btn-danger multiple disabled" onclick="removeAll()">
		            <i class="fa fa-remove"></i> 批量删除
		        </a>
		        <a class="btn btn-warning" onclick="closeItem()">
		            <i class="fa fa-reply-all"></i> 关闭
		        </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var dbData = [[${@baseDbService.selectAll()}]];
		$(function() {
			var options = {
				url: "/system/base/inter/inUser?idUserOuter="+$("#idUserOuter").val(),
				modalName: "接口管理",
				columns: [{
					checkbox: true
				},
					{
						field: 'idInter',
						title: '主键',
						visible: false
					},
					{
						field: 'na',
						title: '名称'
					},
					{
						field: 'euClass',
						title: '分类'
					},
					{
						field: 'idDb',
						title: '数据源',
						formatter: function(value, item, index) {
							var name="";
							$.each(dbData,function (index,entry) {
								if(entry.idDb==parseInt(item.idDb)) {
									name = entry.na;
									return false;
								}
							});
							return name;
						}
					},
					{
						field: 'des',
						title: '备注'
					},
					{
						title: '操作',
						align: 'center',
						formatter: function(value, row, index) {
							var actions = [];
							actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.idInter + '\')"><i class="fa fa-remove"></i>删除</a> ');
							return actions.join('');
						}
					}]
			};
			$.table.init(options);
		});
		
		function queryParams(params) {
			var search = $.table.queryParams(params);
			search.roleId = $("#roleId").val();
			return search;
		}
		
		function selectInter() {
			var url = '/system/outer/selectInter/' + $("#idUserOuter").val();
		    $.modal.open("选择接口", url);
		}
		
		/* 分配用户-批量取消授权 */
		function cancelAuthUserAll(userId) {
		    var rows = $.table.selectFirstColumns();
       		if (rows.length == 0) {
       			$.modal.alertWarning("请至少选择一条记录");
       			return;
       		}
       		$.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
    			var data = { "roleId": $("#roleId").val(), "userIds": rows.join() };
    			$.operate.submit(prefix + "/cancelAll", "post", "json", data);
    		});
		}
		
		/* 分配用户-取消授权 */
		function cancelAuthUser(userId) {
			$.modal.confirm("确认要取消该用户角色吗？", function() {
				$.operate.post(prefix + "/cancel", { "roleId": $("#roleId").val(), "userId": userId });
		    })
		}
	</script>
</body>
</html>